/* Compile with gcc -Wall -O3 -o as1_t2 as1_t2.c dummysort.c
   Then, start ./as1_t2
*/
#include "as1_t2.h"
#include <stdlib.h>

/** Dummy implementation for msort -- remove! */
void msort(task_t** tasks, int count) {
    if(count > 1) {
        int count1 = count/2;
        int count2 = count - count1;
        task_t **tasks2 = &tasks[count1];

        msort(tasks, count1);
        msort(tasks2, count2);

        register int i = 0, j = 0, k = 0;
        task_t **temparray = (task_t**) malloc(sizeof(task_t*) * count);
        while(i < count1 && j < count2) {
            if(tasks[i]->id < tasks2[j]->id) {
                temparray[k++] = tasks[i++];
            }
            else {
                temparray[k++] = tasks2[j++];
            }
        }
        while(i < count1) temparray[k++] = tasks[i++];
        while(j < count2) temparray[k++] = tasks2[j++];
        for(i = 0; i < count; i++) {
            tasks[i] = temparray[i];
        }
        free(temparray);
    }
}
